<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Home extends CI_Controller{

	function  __construct(){
		parent::__construct();
		date_default_timezone_set('PRC');
		$this->load->database();
		$this->load->model('message');		
	}

	public function index(){
		$data['test']=$this->message->getAllMessage();
		$this->load->view("home_view",$data);
	}
	
	public function add(){
		$this->load->helper('url');
		$author = $this->input->post('user');
		$content = $this->input->post('msg');
		$this->message->insertMessage($author, $content);
		redirect('home');
	}
	
	public function delete(){
		$this->load->helper('url');
		$mid = $this->input->get('id');
		$this->message->deleteMessage($mid);
		redirect('home');
	}
	
	public function update(){
		$this->load->helper('url');
		$mid = $this->input->post('id');
		$author = $this->input->post('user');
		$content = $this->input->post('msg');
		$this->message->updateMessage($mid, $author, $content);
		redirect('home');
	}
	
	public function showMessage(){
		$this->load->helper('url');
		$mid = $this->input->get('id');
		$data['msg'] = $this->message->getMessageById($mid);
		$this->load->view('updateMessage_view', $data);
	}
}
?>